package poiTests;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.BeforeClass;
import org.junit.Test;
import poi.GeoInfo;
import poi.POIDatabase;
import poi.POIEditor;

public class POIEditorTest extends TestCase {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@Test
	public void testAddItem() {
		POIEditor edt = new POIEditor(-1);
		assertNotNull(edt);
		edt.setUpdLatitude(5);
		edt.setUpdLongitude(6);
		edt.setUpdLocationName("test");
		edt.setUpdLocationType("Store");
		int id = edt.getUpdLocationID();
		edt.addItem();
		
		edt = new POIEditor(3);
		String oName = edt.getUpdLocationName();
		edt.setUpdLocationName(oName+ "_new");
		edt.addItem();
		
		
		POIDatabase db = new POIDatabase();
		assertTrue(db.connectSource(null));
		GeoInfo val;
		val = db.getItemByID(id);
		assertNotNull(val);
		assertEquals(id+",test,Store,5.0,6.0", val.toString());
		val = db.getItemByID(3);
		assertNotNull(val);
		assertEquals(oName+"_new", val.getLocationName());
		
		assertTrue(db.deleteRecord(id));
		val.setLocationName(oName);
		assertTrue(db.add(val));
		
		val  = db.getItemByID(id);
		assertNull(val);
	}

}
